package cn.tedu.csmall.product.controller;

import cn.tedu.csmall.product.mapper.BrandMapper;
import cn.tedu.csmall.product.pojo.dto.BrandAddNewDTO;
import cn.tedu.csmall.product.pojo.vo.BrandListItemVO;
import cn.tedu.csmall.product.pojo.vo.BrandStandardVO;
import cn.tedu.csmall.product.service.IBrandService;
import cn.tedu.csmall.product.web.JsonResult;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "03. 品牌管理模块")
@RestController
@RequestMapping("/brands")
@Slf4j
public class BrandController {

    @Autowired
    IBrandService service;

    //    http://localhost:9080/brands/add-new?name=测试品牌03&pinyin=拼音&logo=TestLogo&description=TestDescription&keywords=TestKeywords&sort=23&enable=1
    @ApiOperation("添加品牌")
    @ApiOperationSupport(order = 100)
    @PostMapping("/add-new")
    public JsonResult<Void> addNew(@RequestBody BrandAddNewDTO brandAddNewDTO){
        log.debug("开始处理添加品牌请求");
        service.addNew(brandAddNewDTO);
        return JsonResult.ok();
    }

//    http://localhost:9080/brands/21/delete
    @ApiOperation("删除品牌")
    @ApiOperationSupport(order = 200)
    @PostMapping("/{id:[0-9]+}/delete")
    public JsonResult<Void> delete(@PathVariable Long id){
        log.debug("开始处理删除品牌请求");
        service.delete(id);
        return JsonResult.ok();
    }

    @ApiOperation("启用品牌")
    @ApiOperationSupport(order = 300)
    @ApiImplicitParam(name = "id",value = "品牌id",required = true,dataType = "long")
    @PostMapping("/{id:[0-9]+}/enable")
    public JsonResult<Void> setEnable(@PathVariable Long id){
        log.debug("开始处理启用【id={}的品牌】的请求",id);
        service.setEnable(id);
        return JsonResult.ok();
    }

    @ApiOperation("禁用品牌")
    @ApiOperationSupport(order = 301)
    @ApiImplicitParam(name = "id",value = "品牌id",required = true,dataType = "long")
    @PostMapping("/{id:[0-9]+}/disable")
    public JsonResult<Void> setDisable(@PathVariable Long id){
        log.debug("开始处理禁用【id={}的品牌】的请求",id);
        service.setDisable(id);
        return JsonResult.ok();
    }

    @ApiOperation("查询品牌详情")
    @ApiOperationSupport(order = 410)
    @ApiImplicitParam(name = "id",value = "品牌id",required = true,dataType = "Long")
    @GetMapping("/{id:[0-9]+}/detail")
    public JsonResult<BrandStandardVO> getStandardById(@PathVariable Long id){
        log.debug("开始处理查询品牌详情的请求，参数id:{}",id);
        BrandStandardVO brandStandardVO = service.getStandardById(id);
        return JsonResult.ok(brandStandardVO);
    }

    //http://localhost:9080/brands
    @ApiOperation("查询品牌列表")
    @ApiOperationSupport(order = 420)
    @GetMapping("")
    public JsonResult<List<BrandListItemVO>> list(){
        log.debug("开始处理查询品牌请求");
        return JsonResult.ok(service.list());
    }
}
